package com.novice.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutConfig {
    public static final String EXCHANGE_FANOUT_NAME = "exchange_fanout";
    public static final String QUEUE_FANOUT_NAME1 = "fanout.queue1";
    public static final String QUEUE_FANOUT_NAME2 = "fanout.queue2";

    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(EXCHANGE_FANOUT_NAME);
    }
    @Bean
    public Queue queue1() {
        return new Queue(QUEUE_FANOUT_NAME1);
    }

    // 交换机和队列进行绑定
    @Bean
    public Binding fanoutBindQueue1(FanoutExchange fanoutExchange, Queue queue1) {
        return BindingBuilder.bind(queue1).to(fanoutExchange);
    }

    // =========================
    @Bean
    public Queue queue2() {
        return new Queue(QUEUE_FANOUT_NAME2);
    }
    @Bean
    public Binding fanoutBindQueue2(FanoutExchange fanoutExchange, Queue queue2) {
        return BindingBuilder.bind(queue2).to(fanoutExchange);
    }
}
